package com.lab.common;

import lombok.Getter;

/**
 * 自定义业务异常
 * 用于处理可预知的业务错误（如登录失败、权限不足等）
 */
@Getter
public class BusinessException extends RuntimeException {
    /**
     * 错误码
     */
    private final Integer code;

    /**
     * 构造方法（带错误码和消息）
     */
    public BusinessException(Integer code, String message) {
        super(message);
        this.code = code;
    }

    /**
     * 常用业务异常快捷方法
     */
    public static BusinessException loginFailed() {
        return new BusinessException(401, "用户名或密码错误");
    }

    public static BusinessException noPermission() {
        return new BusinessException(403, "没有操作权限");
    }

    public static BusinessException resourceNotFound() {
        return new BusinessException(404, "资源不存在");
    }
}